package controller;


import dao.PatientDao;
import dao.ScheduleDao;
import entity.Patient;
import entity.Schedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import service.ScheduleService;
import util.temp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/schedule")
@Scope("prototype")
public class ScheduleController {

    @Autowired
    private ScheduleDao scheduleDao;
    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private PatientDao patientDao;

    @RequestMapping("/getToDay")
    @ResponseBody
    public Map<String,Object> getToDay(Schedule schedule,int tabinput, @RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize){
        Map<String,Object> map = new HashMap<String,Object>();
        if(tabinput==1){
            map.put("total",scheduleDao.getCount(schedule));
            System.out.println(schedule.getStarTime());
            map.put("rows",scheduleService.getToDay(schedule.getnId(),schedule.getnName(),schedule.getStarTime(),schedule.getEndTime(),pageSize,pageNumber));
            System.out.println(schedule.getStarTime());
            map.put("rows",scheduleService.getToDay(schedule.getnId(),schedule.getnName(),schedule.getStarTime(),schedule.getEndTime(),pageSize,pageNumber));
            return map;
        }
        if(tabinput==2){
            map.put("total",scheduleDao.getTomorrowCount(schedule));
            map.put("rows",scheduleService.getTomorrow(schedule.getnName(),schedule.getStarTime(),schedule.getEndTime(),pageSize,pageNumber));
            return map;
        }
        if(tabinput==3){
            map.put("total",scheduleDao.getNextWeekCount(schedule));
            map.put("rows",scheduleService.getNextWeek(schedule.getnName(),schedule.getStarTime(),schedule.getEndTime(),pageSize,pageNumber));
            return map;
        }
        if (tabinput==4){
            map.put("total",scheduleDao.getAllCount(schedule));
            map.put("rows",scheduleService.getAll(schedule.getnName(),schedule.getStarTime(),schedule.getEndTime(),pageSize,pageNumber));
            return map;
        }
        return null;
    }
    //删除
    @RequestMapping("/del")
    @ResponseBody
    public boolean del(int scheduleid){
        return scheduleDao.del(scheduleid);
    }

    // 查询工作量
    @RequestMapping("/get")
    @ResponseBody
    public Map<String,Object> getAll(){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("Workload",scheduleDao.Workload());
        return map;
    }

 /*   @RequestMapping("/AddCase")
    public boolean JumpPage(String id, HttpServletRequest request, HttpServletResponse response, Model model){
        Patient patient=patientDao.GetPatientByPid(Integer.parseInt(id));
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("pName",patient.getpName());
        map.put("pSex",patient.getpSex());
        map.put("pId",patient.getpId());
        map.put("rDate",new Date());
        request.getSession().setAttribute("p",map);

        return false;
    }*/

}
